﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using RealtorsPortal.Data_Access_Layer;
using RealtorsPortal.Entities;

namespace RealtorsPortal.AdminCP
{
    public partial class ManageProfile : System.Web.UI.Page
    {
        AccountDAL ad = new AccountDAL();
        static Account a;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
               this.LoadAndFillData();
            }
        }

        private void LoadAndFillData()
        {
            string username = Session["adminLogin"].ToString();
            a = ad.GetAccountByUsername(username);
            txtEmail.Text = a.Email;
            txtAddress.Text = a.Address;
            txtFirstName.Text = a.FirstName;
            txtLastName.Text = a.LastName;
            txtPaypal.Text = a.PayPalAccount;
            txtPhone.Text = a.Phone;
            txtCompany.Text = a.Company;
        }

        protected void btnUpdateProfile_Click(object sender, EventArgs e)
        {
            a.Email = txtEmail.Text;
            a.Address = txtAddress.Text;
            a.Company = txtCompany.Text;
            a.FirstName = txtFirstName.Text;
            a.LastName = txtLastName.Text;
            a.Phone = txtPhone.Text;
            a.PayPalAccount = txtPaypal.Text;

            if (ad.UpdateAccount(a))
            {
                lblStatus.Text = "Update successful.";
            }
        }
    }
}